class BlueDevice {
  final String name; //设备名字
  final String address;//设备地址
  final int rssi;//信号
  final String edrAddress;//广播地址
  final int devType;//设备类型
  final int action;//设备类型
  final int connectWay;
  int connectStatus;//连接状态
  final int onBondStatus;//配对状态
  final Map<String, dynamic> cmdParam;

  BlueDevice({
    required this.name,
    required this.address,
    required this.rssi,
    required this.edrAddress,
    required this.devType,
    required this.action,
    required this.connectWay,
    required this.connectStatus,
    required this.onBondStatus,
    required this.cmdParam,
  });

  factory BlueDevice.fromMap(Map map) {
    return BlueDevice(
      name: map['name'] ?? 'Unknown',
      address: map['address'] ?? '',
      rssi: map['rssi'] ?? 0,
      edrAddress: map['edrAddress'] ?? "",
      devType: map['devType'] ?? 0,
      action: map['action'] ?? 0,
      connectWay: map['connectWay'] ?? 0,
      connectStatus: map['connectStatus'] ?? 0,
      onBondStatus: map['onBondStatus'] ?? 0,
      cmdParam: Map<String, dynamic>.from(map['cmdMap'] ?? {}),
    );
  }



  Map<String, dynamic> toJson() {
    return {
      'name': name,
      'address': address,
      'rssi': rssi,
      'edrAddress': edrAddress,
      'devType': devType,
      'action': action,
      'connectWay': connectWay,
      'connectStatus': connectStatus,
      'onBondStatus': onBondStatus,
    };
  }

  @override
  String toString() {
    return '$name - $address - RSSI: $rssi';
  }
}
